import { config } from '../config.js'

class HTTP {
  constructor() {
    this.baseRestUrl = config.api_base_url
  }

  request(url,data,method) {
    return new Promise((resolve, reject) => {
      this._request(url, resolve, reject, data, method)
    })
  }
  _request(url, resolve, reject, data = {}, method = 'GET') {
    var that = this
    var url = this.baseRestUrl + url
    wx.request({
      url: url,
      data: data,
      method: method,
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token'),
        'Cookie': 'MEETREND_CRM_TOKEN=' + wx.getStorageSync('token'),
      },
      success: function (res) {
        resolve(res)
      },
      fail: function (err) {
        reject(err)
      }
    });
  }
};

export { HTTP };